<?php
class Member_groupAction extends IntesysAction {
	public function index(){
        $map['site_id']=__SITEID__;
        //$map['user_id']=session(C('USER_AUTH_KEY'));
		
		if($this->_get('keywords')){
			$map['title'] = array('like', '%'.$this->_get('keywords').'%');
			
		}
		
		
		$pid_list=$this->dao->getList2(0,0,$map);
		$this->assign('pid_list',$pid_list);
		$this->display();
	}
	
	
	public function letter(){
		$this->text = M('Member_group') -> where(array('id' => $this->memberInfo['group_id'])) -> getField('letter');
		$this->display();
	}
	public function editletter(){
		$this->text = M('Member_group') -> where(array('id' => $this-> _get('id'))) -> getField('letter');
		$this->display();
	}
	
	public function delete(){
		if($this->_get('id')){
			$map['pid']=$this->_get('id');
			$re=$this->dao->where($map)->find();
			if($re){
				$this->error('该分类包含了子导航,请先删除子导航');
			}else{
				$all=$this->dao->where('id in('.$this->_get('id').')')->select();
				
				parent::delete();
			}
		}
	}
	public function add(){
        $map['site_id']=__SITEID__;
		$this->pid_list=$this->dao->getList2(0,0,$map);
		parent::add();
	}
	public function edit(){
		$map['site_id']=__SITEID__;
		$this->pid_list=$this->dao->getList2(0,0,$map);
		
		
		parent::edit();
	}
	
	//重写更新方法,防止用户选择自己作为父分类
	public function update(){
		if($this->_post('pid')==$this->_post('id')){
			$this->error('您不能选择当前分类作为父类');
		}else{
			parent::update();
		}
	}
	public function insert(){
		$_POST['site_id'] =__SITEID__;
		$_POST['user_id'] = session(C('USER_AUTH_KEY'));
		parent::insert();
	}
	//邀请的页面
	public function invite(){
		$this->table=$this->dao->where('site_id='.__SITEID__)->select();
		$this->display();
	}
	//设置和获取邀请链接
	public function getInvite(){
		if($this->_get('id')){
			$groupCode=substr(md5($this->_get('id').date('Ymd',time()).'static'),0,6);
			//$memberCode=substr(md5($this->UserInfo.date('Ymd',time()).'static'),0,6);
			$this->dao->where(['id'=>$this->_get('id')])->setField('invitationCode',$groupCode);
			//D('Member')->where(['id'=>$this->UserInfo])->setField('InvitationCode',$memberCode);
			echo(json_encode(['statu'=>1,'tbody'=>'http://weixin.xb363.com'.U('Public/signin',['pid'=>$this->UserInfo,'gid'=>$this->_get('gid'),'code'=>$groupCode])]));
		}
	}
	
	
	 public function expage(){
		 $this->table=$this->dao->where('site_id='.__SITEID__)->select();
		 if($_GET['symbol']=='1'){
			 $this->submitbtn="<div  style='text-align: center;padding-top:60px;'><button id='export_button' class='btn btn-primary btn-sm btnreset' type='button'>保存</button></div>";
		 }else{
			 $this->submitbtn="";
		 }
		$this->display();
		}
}
   


?>